home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + prio.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
- #ifndef PRIOH
- #define PRIOH
-
- //------------------------------------------------------------------------------
- // priority queues implemented by fibonacci heaps
- //
- // Stefan Naeher (1989)
- //------------------------------------------------------------------------------
-
- #include <LEDA/basic.h>
-
- #ifndef FHEAPH
- #include <LEDA/f_heap.h>
- #endif
-
- typedef f_heap_item pq_item;
-
- #define priority_queue(ktype,itype) name3(itype,ktype,priority_queue)
-
-
- #define priority_queuedeclare2(ktype,itype)\
- \
- struct priority_queue(ktype,itype) : public f_heap \
- {\
- int cmp(ent& x, ent& y) const { return compare(*(itype*)&(x),*(itype*)&y); }\
- void print_key(ent& x) const { Print(*(itype*)&x); }\
- void print_inf(ent& x) const { Print(*(ktype*)&x); }\
- void clear_key(ent& x) const { Clear(*(itype*)&x); }\
- void clear_inf(ent& x) const { Clear(*(ktype*)&x); }\
- void copy_key(ent& x) const { Copy(*(itype*)&x); }\
- void copy_inf(ent& x) const { Copy(*(ktype*)&x); }\
- \
- pq_item insert(ktype k,itype i) { return f_heap::insert(Ent(i),Ent(k));}\
- \
- void del_min(ktype& k, itype& i) { k = key(find_min());\
- i = inf(find_min());\
- f_heap::del_min(); }\
- \
- ktype del_min() { ktype x = key(find_min()); f_heap::del_min(); return x; }\
- ktype delete_min(){ ktype x = key(find_min()); f_heap::del_min(); return x; }\
- ktype key(pq_item x) const { return ktype(f_heap::inf(x)); }\
- itype inf(pq_item x) const { return itype(f_heap::key(x)); }\
- itype info(pq_item x) const { return itype(f_heap::key(x)); }\
- void change_key(pq_item x, ktype k) { f_heap::change_inf(x,Ent(k)); }\
- void decrease_inf(pq_item x,itype i){ f_heap::decrease_key(x,Ent(i)); }\
- \
- priority_queue(ktype,itype)() {}\
- priority_queue(ktype,itype)(const priority_queue(ktype,itype)& Q)\
- : f_heap((f_heap&)Q) {}\
- \
- priority_queue(ktype,itype)& operator=(const priority_queue(ktype,itype)& Q)\
- { f_heap::operator=((f_heap&)Q); return *this; }\
- \
- ~priority_queue(ktype,itype)() { clear(); }\
- };
-
- #define forall_pq_items(i,Q) for(i = (Q).first_item(); i; i=(Q).next_item(i))
-
- #endif
-
-